import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class CategoryData {
	private ArrayList<Table> tables;
   private int [] tableKeywords;
	
	public CategoryData(ArrayList<String> filepaths) {
		this.tables = new ArrayList<Table>();
		for(String path : filepaths) {
			Table table = new Table(path);
			tables.add(table);
		}

     tableKeywords = new int[ tables.size() ];
	}
	
   public int categoryContains( ArrayList <String> keywords ){ 
	  int counter = 0;
	  
      for (int i=0; i<tables.size(); i++){
            Table catTable = tables.get(i);
   
            // Determines how many matches there were based on the 
            // table.
            // ArrayList index and Keyword index should match.
            tableKeywords[i] = catTable.tableContains( keywords );
            
            counter += tableKeywords[i];
      }// end for(...)
 
      return counter ;	// Return total matches
    }

    private int max() {
      int val = tableKeywords[0];

      for(int i=1; i < tableKeywords.length; i++) {

      if ( tableKeywords[i] > val )
      { val = tableKeywords[i]; }

      } // end for(...) 

      return val; 
     }

   public String getTablePath( int i )
   {   return tables.get(i).getFilePath();   }

	@Override
	public String toString() {
		String string = "";
		for(Table table: tables) {
			string += table.toString() + "\n";
		}

		return string;
	}

}